import axios from "axios";
import { getToken } from "./auth";

const instance = axios.create({
    baseURL: "http://localhost:3009",
    timeout: 5000,
});

instance.interceptors.request.use(
    function (config) {
        config.headers["authorization"] = "Bearer " + getToken();
        return config;
    },
    function (error) {
        return Promise.reject(error);
    }
);

/**
 * get请求
 * @param {*} url   请求地址
 * @param {*} params url参数
 */
export function get(url, params) {
    return axios.get(url, {
        params,
    });
}

/**
 * post请求
 * @param {*} url 请求地址
 * @param {*} data 数据
 */
export function post(url, data) {
    return axios.post(url, data);
}

/**
 * put请求
 * @param {*} url
 * @param {*} data
 */
export function put(url, data) {
    return axios.put(url, data);
}

/**
 *delete请求
 *
 * @export
 * @param {*} url
 * @returns
 */
export function del(url) {
    return axios.delete(url);
}
